package Sort;
import java.util.Arrays;

public class InsertionSort {

    public void operation(int[] arr) {
        for (int i = 1; i < arr.length; i++) {
            int tmp = arr[i];
            int j = i - 1;
            for (; j >= 0; j--) {
                if (arr[j] > tmp) {
                   arr[j + 1] = arr[j];
                } else {
                    break;
                }
            }
            arr[j + 1] = tmp;
        }
    }

    public static void main(String[] args) {
        int[] arr = {9,8,7,6,5,4,3,2,1};

        InsertionSort insertionSort = new InsertionSort();
        insertionSort.operation(arr);
        System.out.println(Arrays.toString(arr));
    }
}
